<template>
	<view class="index-box">
		<!-- 百度识图 -->
		<!-- 		<sww-search :custom-style="{ paddingBottom: '12rpx' }" @change="onSearch" historyKey="flash_search_history">
			<u-tabs :active-color="vuex_config.themeColor1" :list="tabList" bar-width="60" :gutter="20" :current="tabAct" @change="tabChange"></u-tabs>
		</sww-search> -->
		<prod-list :dataList="dataList" :layout="1"></prod-list>
		<sww-load-more :params="dataListParams" @load="$loadMore"></sww-load-more>
		<sww-login></sww-login>
	</view>
</template>

<script>
import { pageShare } from '@/mixins/pageShare';
import prodList from '@/pagecomponents/prodList/index.vue';
export default {
	mixins: [pageShare],
	components: {
		prodList
	},
	data() {
		return {
			dataListParams: {
				loading: false,
				init: false,
				len: 0,
				loadMore: true
			},
			dataList: [],
			pageNo: 0,
			Page_Count: 2,
			resPath: ''
		};
	},
	onLoad(options) {
		this.resPath = options.resPath;
		this.$initPage();
	},
	onShareAppMessage() {
		this.getShareAppMessage();
	},
	onReachBottom() {
		this._load_data();
	},
	methods: {
		$initPage() {
			this.$loading();
			this.dataList = [];
			this.pageNo = 0;
			this._load_data();
		},
		_load_data() {
			if (this.pageNo < this.Page_Count) {
				this.pageNo += 1;
				this.dataListParams.loading = true;
				uni.uploadFile({
					url: this.vuex_businessObj.resquest + `/webapi/BaiduProductSearch?business_id=${this.vuex_business.pk_id}&page=${this.pageNo}`,
					filePath: this.resPath,
					name: 'file_info',
					success: res => {
						let obj = JSON.parse(res.data || {});
						if (obj.Status == 1) {
							this.dataList = this.dataList.concat(obj.Data || [])
							this.Page_Count = obj.Page_Count;
						}
						this.dataListParams.len = this.dataList.length;
					},
					fail(err) {
						console.error(err);
					},
					complete: () => {
						this.dataListParams.loading = false;
						this.dataListParams.init = true;
						this.$hide();
					}
				});
			} else {
				this.dataListParams.loadMore = false;
			}
		},
		$loadMore() {
			this._load_data();
		}
	}
};
</script>

<style scoped lang="scss"></style>
